package nio.file;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.nio.ByteBuffer;
import java.nio.channels.FileChannel;

/**
 * 使用fileChannel读取数据
 * */
public class NIOFileChannel02 {

    public static void main(String[] args) throws Exception {
        FileInputStream fileInputStream = new FileInputStream("G:\\nio\\1.txt");
        FileChannel fileChannel = fileInputStream.getChannel();
        ByteBuffer byteBuffer = ByteBuffer.allocate(1024);
        fileChannel.read(byteBuffer);
        byteBuffer.flip();
        System.out.println(new String(byteBuffer.array()));
        fileChannel.close();
        fileInputStream.close();
    }
}
